//
//  UIButton+RX.swift
//  mmda
//
//  Created by 李陆涛 on 2018/5/4.
//  Copyright © 2018年 mmda. All rights reserved.
//

import RxSwift
import RxCocoa
import UIKit

extension Reactive where Base: UIButton {
    
    var isOKWithBGColor: Binder<Bool> {
        
        return Binder(base) {
            btn, enable in
            
            btn.isEnabled = enable
            btn.backgroundColor = enable ? kTitleColor : kContentColor
        }
    }

//    var isOKWithTextColor: Binder<Bool> {
//
//        return Binder(base) {
//            btn, enable in
//
//            btn.isEnabled = enable
//            btn.titleLabel?.textColor = enable ? kTitleColor : kContentColor
//        }
//    }
    
    var isOKWithTextAndTextColor:Binder<(Bool,Int)> {

        return Binder(base) {
            
            btn, params in
  
    
            let (enable,tag) = params
            
            btn.isEnabled = enable
            
            btn.setTitleColor(enable ? kTitleColor : kContentColor, for: .normal)
            
            if tag > 60 {
                
                btn.setTitle("发送验证码", for: .normal)
            } else if tag == 60 {

                btn.setTitle("重新发送", for: .normal)
            } else {

                btn.setTitle("重新发送(\(tag))", for: .normal)
            }
        }
    }
    
    
}
